import 'package:app/util/StringUtils.dart';
import 'package:flutter/material.dart';

class TextInput extends TextFormField{

  TextInput({
    super.key,
    FormFieldValidator? validator,
    TextEditingController? controller,
    void Function(String value)? onChanged,
    FocusNode? focusNode,
    bool? enabled = true,
    bool? readOnly = false,
    String? initialValue,
    void Function()? onClick,
    String? placeholder,
    Widget? suffixIcon,
    void Function()? onTap,
    Color? prefixIconColor,
    TextAlign? textAlign,
    Function(String value)? onEntry,
    bool? obscureText
  }) : super(
    onFieldSubmitted: onEntry,
    validator: validator,
    controller: controller,
    onChanged: onChanged,
    focusNode: focusNode,
    enabled: enabled??true,
    readOnly: readOnly??false,
    initialValue: initialValue,
    onTap: onClick,
    obscureText: obscureText??false,
    textAlign: textAlign??TextAlign.start,
    style: TextStyle(
        color: StringUtils.isNotNull(enabled) ?
        !enabled! ? Colors.grey : Colors.black : Colors.black,
        fontWeight: FontWeight.w600,
    ),
    decoration: InputDecoration(
      // filled: true,
      // contentPadding: const EdgeInsets.only(top: 0),
      border: const UnderlineInputBorder(
        borderSide: BorderSide(
            width: 1,
            style: BorderStyle.solid,
            color: Color.fromARGB(255, 243, 243, 243)
        ),
      ),
      enabledBorder: const UnderlineInputBorder(
        borderSide: BorderSide(
            width: 1,
            style: BorderStyle.solid,
            color: Color.fromARGB(255, 243, 243, 243)
        ),
      ),
      disabledBorder: const UnderlineInputBorder(
        borderSide: BorderSide(
            width: 1,
            style: BorderStyle.solid,
            color: Color.fromARGB(255, 243, 243, 243)
        ),
      ),
      focusedBorder: const UnderlineInputBorder(
        borderSide: BorderSide(
            width: 1,
            style: BorderStyle.solid,
            color: Color.fromARGB(255, 243, 243, 243)
        ),
      ),
      errorBorder: const UnderlineInputBorder(
        borderSide: BorderSide(
            width: 1,
            style: BorderStyle.solid,
            color: Color.fromARGB(255, 243, 243, 243)
        ),
      ),
      focusedErrorBorder: const UnderlineInputBorder(
        borderSide: BorderSide(
            width: 1,
            style: BorderStyle.solid,
            color: Color.fromARGB(255, 243, 243, 243)
        ),
      ),
      errorStyle: const TextStyle(fontSize: 16),
      hintText: placeholder??'请输入',
      hintStyle: const TextStyle(
          color: Color.fromARGB(255, 164, 164, 164),
          fontWeight: FontWeight.w500,
      ),
      suffixIcon: suffixIcon != null ? GestureDetector(
        onTap: onTap,
        child: suffixIcon,
      ) : null,
      suffixIconColor: prefixIconColor ?? Colors.grey,
    ),
  );
}